unit GandClass;

interface
uses Classes, SysUtils, CardClass, AdDraws,AdClasses,AdTypes;

const
  COUNT_GAND_CARD = 5;

type
  TGand = class
    private
      FCount:Integer;
      FArray:array of TCard;
      FPlayer:Boolean;
      FConsole:string;
      FShowConsole:Boolean;
    public
      //constructor Create;
      function GetCard(Index:Integer):TCard;
      procedure Add(vCard:TCard);
      property Items[Index:Integer]:TCard read GetCard; default;
      procedure Remove(Index:Integer);
      property Count:Integer read FCount;
      procedure Draw(vAdDraw:TAdDraw;vImageList:TAdImageList;X,Y:Integer);
      property IsPlayer:Boolean read FPlayer write FPlayer;
      property Console:string read FConsole write FConsole;
      property ShowConsole:Boolean read FShowConsole write FShowConsole;
  end;

implementation

procedure TGand.Draw(vAdDraw:TAdDraw;vImageList:TAdImageList;X,Y:Integer);
var
  i, DeltaX,DeltaY:Integer;
begin
    DeltaX:=X;
    DeltaY:=Y;
    for I := 0 to Self.FCount - 1 do
    begin
      DeltaX:=X+(i * CARD_WIDTH);
      if Self.FPlayer then
        vImageList.Find('card').Draw(vAdDraw,DeltaX,DeltaY,Self.FArray[i])
        else
        begin
          DeltaX:=X+(i * Round(CARD_WIDTH/4));
          vImageList.Find('rubashka').Draw(vAdDraw,DeltaX,DeltaY,0);

        end;
    end;
    if Self.ShowConsole then
    begin
      vAdDraw.Canvas.TextOut(X,Y-30,Self.FConsole);
    end;
end;

procedure TGand.Remove(Index: Integer);
begin
  Self.FArray[Index]:=Self.FArray[Self.FCount-1];
  Self.FCount:=Self.FCount-1;
  SetLength(Self.FArray,Self.FCount);
end;

function TGand.GetCard(Index: Integer):TCard;
begin
  Result:=Self.FArray[Index];
  //Self.Remove(Index);
end;

procedure TGand.Add(vCard: Integer);
begin
  if Self.FCount<COUNT_GAND_CARD then
  begin
    Self.FCount:=Self.FCount+1;
    SetLength(Self.FArray,Self.FCount);
    Self.FArray[Self.FCount-1]:=vCard;
  end;
end;

end.
